package com.mercury.rabbitmq.controller;


import com.mercury.rabbitmq.config.business.BusinessBuilder;
import com.mercury.rabbitmq.config.delay.DelayedBuilder;
import com.mercury.rabbitmq.domain.RabbitMqMessage;
import com.mercury.rabbitmq.manager.RabbitMqManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author mercury
 */
@RestController
public class MercuryController {


    @Resource
    private RabbitMqManager rabbitMqManager;

    @GetMapping("/sendMsg")
    public void sendMsg() {

        RabbitMqMessage rabbitMqMessage = new RabbitMqMessage();

        rabbitMqMessage.setData("mercury");

        rabbitMqManager.sendMsg
                ("mercuryExchange", "mercuryRoutingMsg", rabbitMqMessage);
    }


    @GetMapping("/sendDelayedMsg")
    public void sendDelayedMsg() {

        RabbitMqMessage rabbitMqMessage = new RabbitMqMessage();

        rabbitMqMessage.setData("mercury delayed");

        rabbitMqManager.sendDelayedMsg(
                DelayedBuilder.DEFAULT_DELAYED_EXCHANGE,
                DelayedBuilder.DEFAULT_DELAYED_ROUTING_KEY,
                100000,
                rabbitMqMessage);

    }

    @GetMapping("/sendDeadLetterMsg")
    public void sendDeadLetterMsg() {
        RabbitMqMessage rabbitMqMessage = new RabbitMqMessage();

        rabbitMqMessage.setData("mercury dead letter");

        rabbitMqManager.sendDeadLetterMsg(
                BusinessBuilder.BUSINESS_EXCHANGE,
                BusinessBuilder.BUSINESS_QUEUE_ROUTING_KEY,
                30000,
                rabbitMqMessage
        );
    }
}
